package com.coder520.topic.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.management.Query;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.coder520.topic.entity.TabTopic;
import com.coder520.topic.service.TabTopicService;

@Controller
@RequestMapping("/tabTopic")
public class TabTopicController {
	
	@Autowired
	private TabTopicService tabTopicService;
	
	@RequestMapping("/query")
	@ResponseBody
	public List<TabTopic> query(HttpServletRequest request) {
		Map<String, String> map=new HashMap<String, String>();
		
		return tabTopicService.query(map);
	}
	
	/*
	 *保存之后跳转列表页面
	 */
	@RequestMapping("/save")
	public String save(@RequestBody TabTopic tabTopic) {
		tabTopicService.save(tabTopic);
		return "视图页面";
	}
	
	/**
	 *编辑跳转 查询数据并且进行视图跳转使用el表达式可以取值
	 * @param request
	 * @return
	 *	2018年12月16日
	 */
	@RequestMapping("/edit")
	public ModelAndView edit(HttpServletRequest request) {
		String tabTopicId = request.getParameter("tabTopicId");
		TabTopic tabTopic = tabTopicService.queryById(tabTopicId);
		Map map=new HashMap<>();
		map.put("param",tabTopic);
		return new ModelAndView("编辑页面",map);
	}
	/**
	 * 使用ajax异步请求删除
	 * @return
	 *	2018年12月16日
	 */
	@RequestMapping("/delete")
	@ResponseBody
	public String delete(HttpServletRequest request) {
		// TODO Auto-generated method stub
		String tabTopicId = request.getParameter("tabTopicId");
		
		return tabTopicService.delete(tabTopicId)+"";
	}
}
